<template>
  <div class="workCalendar">
    <el-row type="flex" justify="end">
      <!-- 年份 -->
      <el-select v-model="currentYear" size="small" style="width: 120px" @change="dateChange">
        <el-option v-for="item in yearList" :key="item" :label="item" :value="item" />
      </el-select>
      <!-- 月份 -->
      <el-select v-model="currentMonth" style="width:120px" size="small" @change="dateChange">
        <el-option v-for="item in 12" :key="item" :label="item" :value="item" />
      </el-select>
    </el-row>
    <!-- 日历 -->
    <el-calendar v-model="value">
      <template slot="dateCell" slot-scope="{data ,date}">
        <span class="dot">{{ data.day.split('-')[2] }}</span>
        <span v-if="isWeek(date)" class="week">休</span>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  props: {
    currentDate: {
      type: Date,
      default: () => new Date()
    }
  },
  data() {
    return {
      value: this.currentDate,
      currentYear: this.currentDate.getFullYear(), // 当前月份
      currentMonth: this.currentDate.getMonth() + 1 // 当前年份
    }
  },
  computed: {
    yearList() {
      return Array.from(new Array(11), (item, index) => {
        return this.currentYear - index + 5
      })
    }
  },
  methods: {
    isWeek(date) {
      return [6, 0].includes(date.getDay())
    },
    dateChange() {
      this.value = new Date(`${this.currentYear}-${this.currentMonth}-1`)
    }
  }
}
</script>

<style lang="scss" scoped>
.workCalendar {
  ::v-deep .el-calendar__header {
    display: none;
  }
  ::v-deep .el-calendar-table td {
    border: none;
  }
  ::v-deep .el-calendar-day {
    display: flex;
    justify-content: center;
    align-items: center;
    .week {
      width: 20px;
      height: 20px;
      border-radius: 10px;
      background-color: #fa7c4d;
      color: #fff;
      line-height: 20px;
      text-align: center;
    }
  }
  ::v-deep .is-selected {
    .el-calendar-day {
      .dot {
        background-color: #4979fb;
        color: #fff;
        display: inline-block;
        width: 30px;
        height: 30px;
        border-radius: 15px;
        line-height: 30px;
        text-align: center;
      }
    }
  }
}
</style>

